export default {
  name: 'OrderDetail',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    orderId: {
      type: [String, Number],
      default: ''
    },
    orderDetail: Object
  },
  data() {
    return {
      orderInfo: {
        orderNo: '',
        createTime: '',
        status: '',
        deceasedName: '',
        deceasedGender: '',
        deceasedAge: '',
        serviceAddress: '',
        contactPhone: '',
        items: [],
        totalAmount: 0,
        discount: 0,
        remark: '',
        activities: []
      },
      // formData: this.billData.formData,
      // orderDetail.items: this.billData.orderDetail.items,
      // totalAmount: this.billData.totalAmount,
    }
  },
  methods: {
    onClose() {
      this.$emit('onClose')
    },
    // 判断是否显示单元格
    shouldShowCell(index, type) {
      const item = this.orderDetail.items[index]
      const prevItem = index > 0 ? this.orderDetail.items[index - 1] : null

      switch (type) {
        case 'categoryLevel1':
          return !prevItem || prevItem.categoryLevel1 !== item.categoryLevel1
        case 'categoryLevel2':
          return !prevItem ||
            prevItem.categoryLevel1 !== item.categoryLevel1 ||
            prevItem.categoryLevel2 !== item.categoryLevel2
        case 'index':
          return !prevItem || prevItem.categoryLevel1 !== item.categoryLevel1
        default:
          return true
      }
    },
    // 获取合并的行数
    getRowspan(index, type) {
      const item = this.orderDetail.items[index]
      let count = 1

      switch (type) {
        case 'categoryLevel1':
          // 计算相同类别的行数
          for (let i = index + 1; i < this.orderDetail.items.length; i++) {
            if (this.orderDetail.items[i].categoryLevel1 === item.categoryLevel1) {
              count++
            } else {
              break
            }
          }
          break
        case 'categoryLevel2':
          // 计算相同子类的行数
          for (let i = index + 1; i < this.orderDetail.items.length; i++) {
            if (this.orderDetail.items[i].categoryLevel1 === item.categoryLevel1 &&
              this.orderDetail.items[i].categoryLevel2 === item.categoryLevel2) {
              count++
            } else {
              break
            }
          }
          break
        case 'index':
          // 序号与类别合并行数相同
          return this.getRowspan(index, 'categoryLevel1')
      }
      return count
    },
  }
}